package com.fanhang.samples.spring.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

import com.fanhang.samples.spring.web.po.User;

@Controller
@RequestMapping(value = "/response")
public class ResponseController {

	@RequestMapping(value = "/", method = { RequestMethod.GET })
	public String index(Model model) {
		model.addAttribute("message", "This is user list");
		return "index";
	}
	
	@RequestMapping(value = "/add", method = { RequestMethod.GET })
	public String add(HttpServletRequest request, Model model) {
		User user = new User();
		
		model.addAttribute("userModel", user);

		// 页面上radiobuttons,checkboxes,select的items数据源
		return "form/form-sample";
	}
	
	@RequestMapping(value = "/login", method = { RequestMethod.GET })
	public void loginPage(HttpServletRequest request, Model model) {
//		return "form/form-sample";
	}
	
	@RequestMapping(value = "/login", method = { RequestMethod.POST })
	public String login(HttpServletRequest request, Model model) {
		return "form/form-sample";
	}

	@RequestMapping(value = "/show", method = { RequestMethod.POST })
	public String show(HttpServletRequest request, Model model, User user) {
		// 因为add/show这二个action，我们共用了一个页面，所以下面这三个集合，必须手动再添加一次，否则UI界面上，items数据源为null，页面报错
		model.addAttribute("userModel", user);
		
		return "form/form-sample";
	}

}
